#ifndef INC_LIST_H
#define INC_LIST_H

/**
 * list_node_t should be the first element of a struct,
 * in order to share the address with the host struct.
 */

#define LIST_NODE_AS(ptr, type) \
    ((type) (ptr))

typedef struct list_node {
    struct list_node *next;
    struct list_node *prev;
} list_node_t;

typedef struct {
    list_node_t *head;
    list_node_t *tail;
} list_t;

void list_init(list_t *li);
void list_node_init(list_node_t *node);

int list_empty(list_t *li);
int list_single(list_t *li);

void list_push_front(list_t *li, list_node_t *node);
void list_push_back(list_t *li, list_node_t *node);
void list_pop_front(list_t *li);
void list_pop_back(list_t *li);

void list_remove(list_t *li, list_node_t *node);

#endif